﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using System.Linq;


namespace QuanLyThuVien.DAO
{
    class ThanhLyDAO
    {
        public static void Them(ThanhLy TL)
        {
            NorthwindDataContext context = new NorthwindDataContext();
            ThanhLy a = new ThanhLy();
            a.MaNhanVien = TL.MaNhanVien;
            a.NgayThanhLy = TL.NgayThanhLy;
            context.ThanhLies.InsertOnSubmit(a);
            context.SubmitChanges();
        }

        public static void Sua(ThanhLy TL)
        {
            NorthwindDataContext context = new NorthwindDataContext();
            ThanhLy a = context.ThanhLies.Single(sTL => sTL.MaThanhLy == TL.MaThanhLy);
        //    a.MaNhanVien = TL.MaNhanVien;
            a.NgayThanhLy = TL.NgayThanhLy;
            context.SubmitChanges();
        }


        public static DataGridView GetThanhLy(DateTime NTL, int MaNhanVien)
        {
            NorthwindDataContext db = new NorthwindDataContext();
            DataGridView dt = new DataGridView();
            var sql = from TL in db.ThanhLies where TL.NgayThanhLy == NTL && TL.MaNhanVien == MaNhanVien select TL;
            dt.DataSource = sql;
            return dt;
        }


        public static void Xoa(ThanhLy TL)
        {
            NorthwindDataContext context = new NorthwindDataContext();
            ThanhLy a = context.ThanhLies.Single(sTL => sTL.MaThanhLy == TL.MaThanhLy);
            context.ThanhLies.DeleteOnSubmit(a);
            context.SubmitChanges();

        }
    }
}
